package grpc

import (
	"context"
	rewardv1 "jk-time/webook/api/proto/gen/reward/v1"
	"jk-time/webook/reward/domain"
	"jk-time/webook/reward/service"
)

type RewardServiceServer struct {
	rewardv1.UnimplementedPaymentSerivceServer
	svc *service.RewardService
}

func (r *RewardServiceServer) PreReward(ctx context.Context, req *rewardv1.PreRewardRequest) (*rewardv1.PreRewardResponse, error) {
	codeURL, err := r.svc.PreReward(ctx, domain.Reward{
		Uid: req.Uid,
		// 因为什么而打赏
		Biz:   req.Biz,
		BizId: req.BizId,
		// 作为一个可选的东西
		// 也就是你要打赏的东西是什么
		BizName:   req.BizName,
		TargetUid: req.TargetId,
		Amt:       req.Amt,
	})
	if err != nil {
		return nil, err
	}
	return &rewardv1.PreRewardResponse{CodeUrl: codeURL}, nil
}
